package com.alm.token.ui.fragmentDialog;

import android.app.Dialog;
import android.content.DialogInterface;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.alm.token.R;
import com.alm.token.ui.data.bean.UserWalletData;

/**
 * 作者：
 * 时间： 2017/9/18
 * 描述：    测试1
 */

public class ToBindDialogFragment extends BaseDialogFragment {

    private TextView tvSure, tvCancle, tvContent, tvTitle;
    ClickListener clickListener;
    UserWalletData.DataBean.UserMsgBean userMsgBean;
    public static final int BINDTYPE_MAIL = 1, BINDTYPE_MONIC = 2, BINDTYPE_GOOGLECODE = 3;
    public int type = BINDTYPE_MAIL;

    @Override
    protected int getLayoutId() {
        return R.layout.view_tosetpaypswdialog;
    }

    @Override
    protected void initView(Dialog dialog) {
        tvSure = (TextView) dialog.findViewById(R.id.tv_sure);
        tvCancle = (TextView) dialog.findViewById(R.id.tv_cancle);
        tvTitle = dialog.findViewById(R.id.tv_title);
        tvContent = dialog.findViewById(R.id.tv_content);

        userMsgBean = (UserWalletData.DataBean.UserMsgBean) getDialogBean().getT();

        tvTitle.setText(userMsgBean.getTitle());
        tvContent.setText(userMsgBean.getContent());

        type = getDialogBean().getDialogStatus();
//        tvCancle.setVisibility(type == BINDTYPE_MAIL || type == BINDTYPE_MONIC ? View.GONE : View.VISIBLE);
        tvCancle.setVisibility(View.VISIBLE);

        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickListener != null) {
                    clickListener.Listener("", type);
                }
                if (tvCancle.isShown()) {
                    dismissParent();
                }
            }
        });
        tvCancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismissParent();
            }
        });
    }


    @Override
    public int setThemeRes() {
        return R.style.BottomDialogFragment1;
    }

    private boolean outSidedismiss = true;

    @Override
    protected void setView() {
        dialog.setCanceledOnTouchOutside(tvCancle.isShown());
        final Window window = dialog.getWindow();
        final WindowManager.LayoutParams lp = window.getAttributes();
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.gravity = Gravity.CENTER;

        window.setAttributes(lp);
        if (!tvCancle.isShown()) {
            dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
                @Override
                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                    return keyCode == KeyEvent.KEYCODE_BACK;
                }
            });
        }
    }



    public void setListener(ClickListener clickListener) {
        this.clickListener = clickListener;
    }

    public interface ClickListener {
        void Listener(String name, int potion);
    }
}